package org.orr.budgetpro.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

@Entity
public class ExpenseItem implements BudgetItem, Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue
	Integer expenseItemId;

	@NotBlank
	@Length(max = 20)
	private String description;

	@Min(1)
	@NotNull
	private Integer amount;

	@ManyToOne
	private Budget budget;

	@NotNull
	@ManyToOne
	@Cascade(value = { CascadeType.SAVE_UPDATE, CascadeType.MERGE })
	private ExpenseCategory expenseCategory;

	public ExpenseItem() {
		super();
	}

	public ExpenseItem(Integer expenseItemId, String description,
			Integer amount, ExpenseCategory expenseCategory) {
		super();
		this.expenseItemId = expenseItemId;
		this.description = description;
		this.amount = amount;
		this.expenseCategory = expenseCategory;
	}

	public ExpenseItem(Integer expenseItemId, String description,
			Integer amount, Budget budget, ExpenseCategory expenseCategory) {
		super();
		this.expenseItemId = expenseItemId;
		this.description = description;
		this.amount = amount;
		this.budget = budget;
		this.expenseCategory = expenseCategory;
	}

	public Integer getExpenseItemId() {
		return expenseItemId;
	}

	public void setExpenseItemId(Integer incomeItemId) {
		this.expenseItemId = incomeItemId;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setAmount(Integer amount) {
		this.amount = amount;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public Integer getAmount() {
		return amount;
	}

	public Budget getBudget() {
		return budget;
	}

	public void setBudget(Budget budget) {
		this.budget = budget;
	}

	public ExpenseCategory getExpenseCategory() {
		return expenseCategory;
	}

	public void setExpenseCategory(ExpenseCategory expenseCategory) {
		this.expenseCategory = expenseCategory;
	}

	@Override
	public String toString() {
		return "ExpenseItem [expenseItemId=" + expenseItemId + ", description="
				+ description + ", amount=" + amount + "]";
	}

}
